package data_structures_and_algorithms.tree;

import common.TreeNode;

/**
 * @ClassName Code_0226_invertTree
 * @Description: https://leetcode.cn/problems/invert-binary-tree/
 *
 * 反转二叉树：将node的左右节点交换
 * @Author: yongliang.ma
 * @Create_time:2022/10/26 21:42
 */
public class Code_0226_invertTree {
    public TreeNode invertTree(TreeNode root) {
        dfs(root);
        return root;
    }

    public void dfs(TreeNode node){
        if (node == null){
            return;
        }
        TreeNode temp = node.left;
        node.left = node.right;
        node.right = temp;

        dfs(node.left);
        dfs(node.right);
    }
}
